<include file="Common/header" />
<title>会员录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add" enctype="multipart/form-data">
		<div class="panel panel-primary">
			<div class="panel-header">员工基本信息</div> 
			<table class="table table-border table-bordered table-striped">
	           	<tr>
					<td style="background-color: #f9f9f9;text-align: right">登陆账号：</td>
	                <td style="background-color: white;">
						<input type="text" name="username" id="username" class="input-text radius" value="{$userinfo['username']}" />
	                </td>
	                <td style="background-color: #f9f9f9;text-align: right">登陆密码：</td>
	                <td style="background-color: white">
						<input type="password" name="password" id="password" class="input-text radius" value="" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">姓名：</td>
	                <td style="background-color: white">
						<input type="text" name="nickname" id="nickname" class="input-text radius" value="{$userinfo['nickname']}" />
					</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">身份证：</td>
	                <td style="background-color: white">
						<input type="text" name="card" id="card" class="input-text radius" value="{$userinfo['card']}" />
					</td>
					<td style="background-color: #f9f9f9;text-align: right">常住地址：</td>
	                <td style="background-color: white" colspan="3">
						<input type="text" name="address" id="address" class="input-text radius" value="{$userinfo['address']}" />
					</td>
				</tr>
				<tr>
					<td style="background-color: #f9f9f9;text-align: right">角色名称：</td>
					<td style="background-color: white">
						<span class="select-box radius">
							<select class="select radius" id="roleid" name="roleid">
								<?php foreach($rolelist as $rs){ ?>
									<option value="{$rs['role_id']}" <?php echo $rs['role_id'] == $userinfo['roleid'] ? 'selected' : '';?>>{$rs['role_name']}</option>
								<?php } ?>
							</select>
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right">性别：</td>
					<td style="background-color: white">
						<span class="select-box radius">
							<select class="select radius" id="sex" name="sex">
								<option value="1" {$userinfo['sex'] == 1 ? 'selected' : ''}>男</option>
								<option value="2" {$userinfo['sex'] == 2 ? 'selected' : ''}>女</option>
							</select>
						</span>
					</td>
					<td style="background-color: #f9f9f9;text-align: right">联系方式：</td>
	                <td style="background-color: white">
						<input type="text" name="phone" id="phone" class="input-text radius" value="{$userinfo['phone']}" />
					</td>
				</tr>
				<tr>	
					<td style="background-color: #f9f9f9;text-align: right">选择分店：</td>
					<td style="background-color: white" colspan="5">
						<div class="formControls col-12">
							<dl class="permission-list">
								<dt>
									<label>&nbsp;</label>
								</dt>
								<dd>
									<dl class="cl permission-list2">
										<dt>
											<label class="">
												<input type="checkbox" />  全选/反选
											</label>
										</dt>
										<dd>
											<?php foreach($shoplist as $ls){ ?>
											<label class="">
												<?php if(strpos($shopidlist, ','. $ls['shop_id'] .',') !== false){ ?>
												<input type="checkbox" value="{$ls['shop_id']}" checked /> {$ls['title']}
												<?php }else{ ?>
												<input type="checkbox" value="{$ls['shop_id']}" /> {$ls['title']}
												<?php } ?>
											</label>
											<?php } ?>
										</dd>
									</dl>
								</dd>
							</dl>
						</div>
					</td>
				</tr>
				<tr class="text-c">
					<td colspan="6">
						<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
					</td>
				</tr>
			</table>
		</div>
	</form>
</div>
<script>
	$(document).ready(function(){
		$(".permission-list2 dt input:checkbox").change(function(){
			if($(this).is(':checked')){
				//选中
				$(".permission-list2 dd input:checkbox").each(function(){
					$(this).prop("checked",true);
				});
			}else{
				//取消
				$(".permission-list2 dd input:checkbox").each(function(){
					$(this).prop("checked",false);
				});
			}
		});
		//单个选择
		$(".permission-list2 dd input:checkbox").change(function(){
			var length = $(".permission-list2 dd").find("input:checked").length;
			var total = $(".permission-list2 dd").find("input:checkbox").length;
			if(length == total){
				$(".permission-list2 dt input:checkbox").prop("checked",true);
			}else{
				$(".permission-list2 dt input:checkbox").prop("checked",false);
			}
		});
		
		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var data = {};
			var username = $("#username").val() || "";
			if(username.length <= 0 || username.length > 20){
				layer.msg("请正确输入登陆帐号", {icon: 2, time:2000});
				return false;
			}else{
				data.username = username;
			}
			
			var password = $("#password").val() || "";
			if(password.length <= 0 || password.length > 20){
				layer.msg("请正确输入登陆密码", {icon: 2, time:2000});
				return false;
			}else{
				data.password = password;
			}
			
			var nickname = $("#nickname").val();
			if(nickname.length <= 0 || nickname.length > 11){
				layer.msg('请正确输入姓名', {icon: 2, time: 2000});
				return false;
			}else{
				data.nickname = nickname;
			}

			var phone = $("#phone").val();
			if(phone.length <= 0 || phone.length > 11){
				layer.msg('请正确输入联系方式', {icon: 2, time: 2000});
				return false;
			}else{
				data.phone = phone;
			}
			var card = $("#card").val() || "";
			if(card.length <= 0 || card.length > 18){
				layer.msg('请正确输入身份证号', {icon: 2, time: 2000});
				return false;
			}else{
				data.card = card;
			}
			data.roleid = $("#roleid").val();
			data.sex = $("#sex").val();
			data.address = $("#address").val() || "";
			//获取选择的分店
			var shop_id = [];
			$(".permission-list2 dd").find("input:checked").each(function(){
				shop_id.push($(this).val());
			});
			data.shop_id = shop_id;
			data.userid = "{$userinfo['userid']}";
			var load = layer.load(2);
			$.post('admin_add.html', data, function(res){
				layer.close(load);
				if(res.errCode/1 == 1){
					layer.msg(res.content, {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else{
					layer.msg(data.content, {icon: 2, time: 2000});
				}
			},"JSON");
		});
	});
</script>
</body>
</html>